package com.smart.modules.genealogy.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smart.modules.genealogy.domain.Genealogy;
import com.smart.modules.genealogy.service.IGenealogyService;
import com.smart.system.common.result.Result;
import com.smart.system.common.result.PageResult;


/**
 * 家谱Controller
 */
@RestController
@RequestMapping("/genealogy/genealogy")
public class GenealogyController
{
    @Autowired
    private IGenealogyService genealogyService;


    /**
     * 查询家谱列表
     */
    //@PreAuthorize("@ss.hasPermi('genealogy:genealogy:list')")
    @GetMapping("/list")
    public PageResult list(Genealogy genealogy)
    {

        IPage<Genealogy> pageModel = new Page<Genealogy>(genealogy.getPageNum(),genealogy.getPageSize());
        IPage<Genealogy> page = genealogyService.selectGenealogyList(pageModel,genealogy);
        return PageResult.success(page);
    }


    /**
     * 获取家谱详细信息
     */
    //@PreAuthorize("@ss.hasPermi('genealogy:genealogy:query')")
    @GetMapping(value = "/{genealogyId}")
    public Result getInfo(@PathVariable("genealogyId") Long genealogyId)
    {
        return Result.success(genealogyService.selectGenealogyByGenealogyId(genealogyId));
    }

    /**
     * 新增家谱
     */
    //@PreAuthorize("@ss.hasPermi('genealogy:genealogy:add')")
    @PostMapping
    public Result add(@RequestBody Genealogy genealogy)
    {
        return Result.success(genealogyService.insertGenealogy(genealogy));
    }


    /**
     * 修改家谱
     */
    //@PreAuthorize("@ss.hasPermi('genealogy:genealogy:edit')")
    @PutMapping
    public Result edit(@RequestBody Genealogy genealogy)
    {
        return Result.success(genealogyService.updateGenealogy(genealogy));
    }

    /**
     * 删除家谱
     */
    //@PreAuthorize("@ss.hasPermi('genealogy:genealogy:remove')")
    @DeleteMapping("/{genealogyIds}")
    public Result remove(@PathVariable Long[] genealogyIds)
    {
        return Result.success(genealogyService.deleteGenealogyByGenealogyIds(genealogyIds));
    }
}
